package cn.itsource.pet.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.SearchMasterMessage;
import cn.itsource.pet.domain.SearchMessageDto;
import cn.itsource.pet.query.SearchMasterMessageQuery;
import cn.itsource.pet.service.ISearchMasterMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 寻主审核控制器
 */
@RestController
@RequestMapping("/searchmaster")
@Api(tags = "寻主审核管理", description = "寻主审核操作接口")
public class SearchMasterMessageController {

    @Autowired
    private ISearchMasterMessageService searchMasterMessageService;

    /**
     * 寻主发布审核
     */
    @PostMapping("/shenghe")
    @ApiOperation(value = "审核", notes = "审核")
    public AjaxResult shenghe(@RequestBody SearchMessageDto messageDto) {
        //审核
        return searchMasterMessageService.shenghe(messageDto);
    }

    /**
     * 寻主发布
     */
    @PostMapping("/publish")
    @ApiOperation(value = "寻主发布", notes = "寻主发布")
    public AjaxResult publish(@RequestBody SearchMasterMessage message) {
        //查询分页数据
        return searchMasterMessageService.publish(message);
    }


    /**
     * 查询所有
     */
    @GetMapping
    @ApiOperation(value = "查询所有寻主审核信息", notes = "查询所有寻主审核信息，get请求")
    public List<SearchMasterMessage> findAll() {
        return searchMasterMessageService.findAll();
    }

    /**
     * 查询分页数据
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "查询部门分页数据", notes = "查询数据")
    public PageList<SearchMasterMessage> findPage(@RequestBody SearchMasterMessageQuery searchMasterMessageQuery) {
        //查询分页数据
        return searchMasterMessageService.findMyPage(searchMasterMessageQuery);
    }

    /**
     * 新增或修改的操作
     * 根据id来区分新增和修改
     * 怎么区分请求使用的请求方式  这里是post
     */
    @PostMapping
    public AjaxResult saveOrUpdate(@RequestBody SearchMasterMessage searchMasterMessage) {

        //没有id就是新增
        searchMasterMessageService.saveOrUpdate(searchMasterMessage);

        //返回成功对象
        return AjaxResult.createSuccess();
    }

    /**
     * 删除操作
     */
    @DeleteMapping("{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {

        searchMasterMessageService.delete(id);
        //返回成功对象
        return AjaxResult.createSuccess();

    }

    /**
     * 批量删除操作
     */
    @PostMapping("/batchDelete")
    public AjaxResult delete(@RequestBody SearchMasterMessageQuery searchMasterMessageQuery) {

        //批量删除操作
        searchMasterMessageService.batchDelete(searchMasterMessageQuery);
        //返回成功对象
        return AjaxResult.createSuccess();
    }


}
